<?php

!defined('IN_HDWIKI') && exit('Access Denied');
class control extends base{

	function control(& $get,& $post){
		$this->base( & $get,& $post);
		$this->load("doc");
		$this->load("category");
		$this->load("user");
		$this->load("usergroup");
		$this->load("synonym");
		$this->load("attachment");
		$this->load("comment");
		eval($this->plugin["ucenter"]["hooks"]["include"]);
	}

	function doview() {
		if(!is_numeric(@$this->get[2])){
			$this->message($this->view->lang['parameterError'],'index.php',0);
		}
		$doc=$_ENV['doc']->get_doc($this->get[2]);
		if(!(bool)$doc){
			$this->message($this->view->lang['docNotExist'],'index.php',0);
		}elseif($synonym=$_ENV['synonym']->get_synonym_by_src(addslashes($doc['title']))){
			$this->header("synonym-view-".$synonym['id']);
		}elseif($doc['visible']=='0' &&!$this->checkable('doc-audit') && $doc['lasteditorid']!= $this->user['uid']){
			if($doc['editions']>1){
				$doc=$_ENV['doc']->get_lastdoc($this->get[2],$doc['lastedit']);
			}else{
				$this->message($this->view->lang['viewDocTip4'],'index.php',0);
			}
		}elseif(@$this->get[3]=="locked"&&$doc['locked']==1){
			$this->view->assign('locked','1');
		}
		$_ENV['doc']->update_field('views',1,$doc['did'],0);
		$this->view->vars['setting']['seo_keywords']=$doc['tag'];
		$this->view->vars['setting']['seo_description']=$doc['summary'];
		$doc['tag']=$_ENV['doc']->spilttags($doc['tag']);
		$editors=$_ENV['usergroup']->get_userstar( array($doc['authorid'],$doc['lasteditorid']) );
		
		eval($this->plugin['ucenter']['hooks']['doc_user_image']);
		
		$author=$editors[$doc['author']];
		if ($doc['lasteditorid'] > 0 && $doc['time'] < $doc['lastedit']){
			$lasteditor = $editors[$doc['lasteditor']];
			$this->view->assign('lasteditor',$lasteditor);
		}
		$doc['lastedit']=date('Y-m-d',$doc['lastedit']);
		$similardoc=$_ENV['doc']->get_similardoc($doc['cid']);
		$category=$_ENV['category']->get_category($doc['cid']);
		$navigation=unserialize($category['navigation']);
		$num=count($navigation);
		$doc['sectionlist']=$_ENV['doc']->splithtml($doc['content']);
		$doc['doctitle'] = $doc['title'];
		$doc['title'] = addslashes($doc['title']);
		$sectionlist=$_ENV['doc']->getsections($doc['sectionlist']);
		$editlock['locked']=$_ENV['doc']->iseditlocked($doc['did']);
		if($editlock['locked']){
			$editlock['user']=$_ENV['user']->get_user('uid',$editlock['locked']);
		}
		eval($this->plugin['hdapi']['hooks']['uniontitle']);
		
		$this->load('adv');
		$advlist=$_ENV['adv']->adv_doc_filter($this->advertisement,$navigation);
		if($advlist){
			$this->view->assign('advlist',$advlist);
		}
		$attachment=$_ENV['attachment']->get_attachment('did',$doc['did']);
		$synonyms=$_ENV['synonym']->get_synonym_by_dest('',$doc['title']);
		$this->view->assign('synonyms',$synonyms);
		$this->view->assign('doc',$doc);
		$this->view->assign('attachment',$attachment);
		$this->view->assign('attach_download',$this->checkable('attachment-download'));
		$this->view->assign('audit',$this->checkable('admin_doc-audit'));
		$this->view->assign('synonym_audit',$this->checkable('synonym-savesynonym'));
		$this->view->assign('navtitle',$doc['doctitle'].'-'.$navigation[$num-1]['name'].'-');
		$this->view->assign("searchtext",$doc['title']);
		$this->view->assign('author',$author);
		$this->view->assign('editlock',$editlock);
		$this->view->assign('sectionlist',$sectionlist);
		$this->view->assign('similardoc',$similardoc);
		$this->view->assign('navigation',$navigation);
		$this->view->display('viewdoc');
	}

	function docreate(){
		if(!isset($this->post['create_submit'])){
			if('0' === $this->user['checkup']){
				$this->message($this->view->lang['createDocTip17'],'BACK',0);
			}
			if(isset($this->post['title'])){
				$this->view->assign('title',$this->post['title']);
			}
			if(@is_numeric($this->get[2])){
				$category=$_ENV['category']->get_category($this->get[2]);
				$this->view->assign("category",$category);
			}
			$this->view->assign('navtitle',$this->view->lang['createDoc']."-");
			$this->view->display('createdoc');
		}else if(!isset($this->post['publish_button'])){
			if(trim($this->post['title'])=="" ){
				$this->message($this->view->lang['createDocTip1'],'BACK',0);
			}
			if($synonym=$_ENV['synonym']->get_synonym_by_src($this->post['title'])){
				$this->header("synonym-view-".$synonym['id']);
			}
			if($_ENV['doc']->have_danger_word($this->post['title'])){
				$this->message($this->view->lang['docHaveDanerWord'],'BACK',0);
			}
			if(!(bool)$_ENV['category']->get_category($this->post['category'])){
				$this->message($this->view->lang['categoryNotExist'],'BACK',0);
			}
			$title=string::substring(string::stripscript($_ENV['doc']->replace_danger_word(trim($this->post['title']))),0,80);
			if(!(bool)$title){
				$this->message($this->view->lang['createDocTip16'],'BACK',0);
			}
			$data=$_ENV['doc']->get_doc_by_title($title);
			if((bool)$data){
				$this->header('doc-view-'.$data['did']);
			}
			$doc['title']=stripcslashes($title);
			$doc['cid']=$this->post['category'];
			eval($this->plugin['hdapi']['hooks']['readcontent']);
			$this->view->assign('navtitle',"$title-".$this->view->lang['createDoc']."-");
			$this->view->assign("page_action","create");
			$this->view->assign("attachment_open",$this->setting['attachment_open']);
			$this->view->assign("attachment_type","['".implode("','",$_ENV['attachment']->get_attachment_type())."']");
			$this->view->assign('attachment_size',$this->setting['attachment_size']);
			$this->view->assign('doc',$doc);
			$this->view->display('editor');
		}else{
			if(@trim($this->post['thcTextarea'])==''||@trim($this->post['title'])==''){
				$this->message($this->view->lang['contentIsNull'],'BACK',0);
			}
			if((bool)$_ENV['doc']->get_doc_by_title($this->post['title'])){
				$this->message($this->view->lang['createDocTip5'],'BACK',0);
			}
			if(!(bool)$_ENV['category']->get_category($this->post['category'])){
				$this->message($this->view->lang['categoryNotExist'],'BACK',0);
			}
			if(@!(bool)$this->post['summary']){
				$doc['summary']=trim(strip_tags($_ENV['doc']->replace_danger_word($this->post['summary'])));
			}
			$doc['letter']=string::getfirstletter($this->post['title']);
			$doc['category']=$this->post['category'];
			$doc['title']=string::substring(string::stripscript($_ENV['doc']->replace_danger_word(trim($this->post['title']))),0,80);
			$doc['tags']=$_ENV['doc']->jointags($this->post['tags']);
			$doc['tags']=$_ENV['doc']->replace_danger_word($doc['tags']);
			$doc['content']=string::stripscript($_ENV['doc']->replace_danger_word($this->post['thcTextarea']));
			$doc['content']= $this->setting['auto_picture']?$_ENV['doc']->auto_picture($doc['content']):$doc['content'];
			$doc['summary']=trim(strip_tags($_ENV['doc']->replace_danger_word($this->post['summary'])));
			$doc['summary']=(bool)$doc['summary']?$doc['summary']:$doc['content'];
			$doc['summary']=trim(string::convercharacter(string::substring(strip_tags($doc['summary']),0,100)));
			$doc['images']=util::getimagesnum($doc['content']);
			$doc['time']=$this->time;
			$doc['words']=string::hstrlen($doc['content']);
			$doc['visible']=$this->setting['verify_doc']?'0':'1';
			if(strpos($this->user['regulars'], 'doc-immunity') !== false || 4 == $this->user['groupid']){
				$doc['visible'] = 1;
			}
			
			foreach($this->post['tags'] as $search_tags){
				$doc['search_tags'] .=string::convert_to_unicode($search_tags).";";
			}
			$did=$_ENV['doc']->add_doc($doc);
			$_ENV['user']->add_credit($this->user['uid'],'doc-create',$this->setting['credit_create']);
			$_ENV['user']->update_field('creates',$this->user['creates']+1,$this->user['uid']);			
			$_ENV['category']->update_category_docs($this->post['category']);
			$message=$_ENV['attachment']->upload_attachment($did);
			eval($this->plugin["ucenter"]["hooks"]["create_feed"]);
			eval($this->plugin['hdapi']['hooks']['postcontent']);
			if((bool)$message){
				$this->message($message,$this->setting['seo_prefix']."doc-view-".$did,0);
			}else{
				$this->message($this->view->lang['docPublishSuccess'],$this->setting['seo_prefix']."doc-view-".$did,0);
			}
		}
	}

	function doverify(){
		$ajaxtitle=string::hiconv(trim($this->post['title']));
		$title=string::substring(string::stripscript(trim($ajaxtitle)),0,80);
		if($_ENV['doc']->have_danger_word($title)){
			$this->message("-1","",2);
		}
		if($ajaxtitle!=string::stripscript($ajaxtitle)){
			$this->message("-2","",2);
		}
		if($synonym=$_ENV['synonym']->get_synonym_by_src($ajaxtitle)){
			$this->message($synonym[destdid]." ".$synonym[desttitle],"",2);
		}
		$data=$_ENV['doc']->get_doc_by_title($title);
		if(!(bool)$data){
			$this->message("1","",2);
		}else{
			$this->message("0","",2);
		}
	}

	function doedit(){
		if('0' === $this->user['checkup']){
			$this->message($this->view->lang['createDocTip17'],'BACK',0);
		}
		@$did=isset($this->get[2])?$this->get[2]:$this->post['did'];
		if(!is_numeric($did)){
			$this->message($this->view->lang['parameterError'],'index.php',0);
		}
		$doc=$_ENV['doc']->get_doc($did);
		if(!(bool)$doc){
			$this->message($this->view->lang['docNotExist'],'index.php',0);
		}
		if($doc['visible']=='0'&&!$this->checkable('doc-audit') && $doc['lasteditorid']!= $this->user['uid']){
			$this->message($this->view->lang['viewDocTip4'],'index.php',0);
		}
		if(!isset($this->post['publish_button'])){
			$editlockuid=$_ENV['doc']->iseditlocked($did);
			if($editlockuid!=0&&$editlockuid!=$this->user['uid']){
				$this->message($this->view->lang['viewDocTip5'].$this->view->lang['viewDocTip6'],'BACK',0);
			}
			eval($this->plugin['hdapi']['hooks']['readcontent']);
			if($doc['locked']){
				$this->header("doc-view-".$doc['did']."-locked");
			}
			$doc['tag']=$_ENV['doc']->spilttags($doc['tag']);
			$attachment=$_ENV['attachment']->get_attachment('did',$doc['did']);
			$this->view->assign('attachment',$attachment);
			$this->view->assign('navtitle',$doc['title'].'-'.$this->view->lang['editDoc'].'-');
			$this->view->assign("page_action","edit");
			$this->view->assign("attachment_power",$this->checkable('attachment-remove'));
			$this->view->assign("attachment_type","['".implode("','",$_ENV['attachment']->get_attachment_type())."']");
			$doc = str_replace("&", "&amp;", $doc);
			$this->view->assign("doc",$doc);
			$this->view->display("editor");
		}else{
			if(trim($this->post['thcTextarea'])==""){
				$this->message($this->view->lang['contentIsNull'],'BACK',0);
			}
			$doc['tags']=$_ENV['doc']->jointags($this->post['tags']);
			$doc['tags']=$_ENV['doc']->replace_danger_word($doc['tags']);
			$doc['content']=string::stripscript($_ENV['doc']->replace_danger_word($this->post['thcTextarea']));
			$doc['content']= $this->setting['auto_picture']?$_ENV['doc']->auto_picture($doc['content']):$doc['content'];
			$doc['summary']=trim(strip_tags($_ENV['doc']->replace_danger_word($this->post['summary'])));
			$doc['summary']=(bool)$doc['summary']?$doc['summary']:$doc['content'];
			$doc['summary'] =trim(string::convercharacter(string::substring(strip_tags($doc['summary']),0,100)));
			$doc['images']=util::getimagesnum($doc['content']);
			$doc['time']=$this->time;
			
			$doc['words']=string::hstrlen($doc['content']);
			$doc['reason']=$_ENV['doc']->jointags($this->post['editreason']);
			foreach($this->post['tags'] as $search_tags){
				$doc['search_tags'] .=string::convert_to_unicode($search_tags).";";
			}
			
			if (0 == $doc['visible'] && $this->user['uid'] == $doc['lasteditorid'] && $this->user['type'] == 2){
				$_ENV['doc']->edit_unaudit_doc($doc);
				$_ENV['doc']->unset_editlock($doc['did'],$this->user['uid']);
				$this->message($this->view->lang['docPublishSuccess'],$this->setting['seo_prefix']."doc-view-".$doc['did'],0);
			}
			
			if( strpos($this->user['regulars'], 'doc-audit') !== false
				|| strpos($this->user['regulars'], 'doc-immunity') !== false
				|| (empty($this->user['regulars']) && $this->user['type'] == 1)
			){
				$doc['visible'] = 1;
			}else{
				$doc['visible']=$this->setting['verify_doc']?'0':'1';
			}
			
			$_ENV['doc']->edit_doc($doc,"1");
			$_ENV['doc']->unset_editlock($doc['did'],$this->user['uid']);
			if($_ENV['doc']->is_addcredit($doc['did'],$this->user['uid'])){
				$_ENV['user']->add_credit($this->user['uid'],'doc-edit',$this->setting['credit_edit']);
			}
			$_ENV['user']->update_field('edits',$this->user['edits']+1,$this->user['uid']);
			$_ENV['attachment']->update_desc($this->post['attachment_id'],$this->post['attachment_desc']);
			if($this->checkable('attachment-remove')){
				$attachmentlist=$_ENV['attachment']->get_attachment('did',$doc['did']);
				for($i=0;$i<count($attachmentlist);$i++){
					if($attachmentlist[$i]['isimage']=="0"&&!in_array($attachmentlist[$i]['id'],(array)$this->post['attachment_id'])){
						@unlink($attachmentlist[$i]['attachment']);
						$remove_attachid[]=$attachmentlist[$i]['id'];
					}
				}
				$_ENV['attachment']->remove($remove_attachid);
			}
			$message=$_ENV['attachment']->upload_attachment($doc['did']);
			eval($this->plugin["ucenter"]["hooks"]["edit_feed"]);
			eval($this->plugin['hdapi']['hooks']['postcontent']);
			if((bool)$message){
				$this->message($message,$this->setting['seo_prefix']."doc-view-".$doc['did'].$this->setting['seo_suffix'],0);
			}else{
				$this->message($this->view->lang['docPublishSuccess'],$this->setting['seo_prefix']."doc-view-".$doc['did'],0);
			}
		}
	}

	function doeditsection(){
		@$did=isset($this->get[2])?$this->get[2]:$this->post['did'];
		@$id=isset($this->get[3])?$this->get[3]:$this->post['section_id'];
		if(!is_numeric($did)||!is_numeric($id)){
			$this->message($this->view->lang['parameterError'],'index.php',0);
		}
		$doc=$_ENV['doc']->get_doc($did);
		eval($this->plugin['hdapi']['hooks']['readcontent']);
		if(!(bool)$doc){
			$this->message($this->view->lang['docNotExist'],'index.php',0);
		}
		if($doc['visible']=='0'&&!$this->checkable('admin_doc-audit')){
			$this->message($this->view->lang['viewDocTip4'],'index.php',0);
		}
		if(!isset($this->post['publish_button'])){
			$editlockuid=$_ENV['doc']->iseditlocked($did);
			if($editlockuid!=0&&$editlockuid!=$this->user['uid']){
				$this->message($this->view->lang['viewDocTip5'].$this->view->lang['viewDocTip6'],'BACK',0);
			}
			if($doc['locked']){
				$this->header("doc-view-".$doc['did']."-locked");
			}
			$array_section=$_ENV['doc']->splithtml($doc['content']);
			if(!isset($array_section[$id+1]['value']))
			$this->header('doc-edit-'.$did);
			$doc['tag']=$_ENV['doc']->spilttags($doc['tag']);
			$doc['content']=$array_section[$id+1]['value'];
			$doc['content']= $this->setting['auto_picture']?$_ENV['doc']->auto_picture($doc['content']):$doc['content'];
			$doc['title']=$doc['title']."-".$array_section[$id]['value'];
			$doc['section_id']=$id;
			$this->view->assign('navtitle',$doc['title'].'-'.$this->view->lang['editionEdit'].'-');
			$this->view->assign("page_action","editsection");
			$doc = str_replace("&", "&amp;", $doc);
			$this->view->assign("doc",$doc);
			$this->view->display("editor");
		}else{
			if(trim($this->post['thcTextarea'])==""){
				$this->message($this->view->lang['contentIsNull'],'BACK',0);
			}
			$tem=$_ENV['doc']->splithtml($doc['content']);
			$tem[$id+1]['value']=$_ENV['doc']->replace_danger_word(stripcslashes($this->post['thcTextarea']));
			$doc['content']=string::haddslashes(string::stripscript($_ENV['doc']->joinhtml($tem)),1);
			$doc['tags']=$_ENV['doc']->jointags($this->post['tags']);
			$doc['summary']=trim(strip_tags($_ENV['doc']->replace_danger_word($this->post['summary'])));
			$doc['summary']=(bool)$doc['summary']?$doc['summary']:$doc['content'];
			$doc['summary'] =trim(string::convercharacter(string::substring(strip_tags($doc['summary']),0,100)));
			$doc['images']=util::getimagesnum($doc['content']);
			$doc['time']=$this->time;
			$doc['visible']=$this->setting['verify_doc']?'0':'1';
			$doc['words']=string::hstrlen($doc['content']);
			$doc['reason']=$_ENV['doc']->jointags($this->post['editreason']);
			foreach($this->post['tags'] as $search_tags){
				$doc['search_tags'] .=string::convert_to_unicode($search_tags).";";
			}
			$_ENV['doc']->edit_doc($doc,"2");
			$_ENV['doc']->unset_editlock($doc['did'],$this->user['uid']);
			if($_ENV['doc']->is_addcredit($doc['did'],$this->user['uid'])){
				$_ENV['user']->add_credit($this->user['uid'],'doc-edit',$this->setting['credit_edit']);
			}
			$_ENV['user']->update_field('edits',$this->user['edits']+1,$this->user['uid']);
			eval($this->plugin['hdapi']['hooks']['postcontent']);

			$this->message($this->view->lang['docPublishSuccess'],$this->setting['seo_prefix']."doc-view-".$doc['did'],0);

		}
	}

	function dorefresheditlock(){
		$_ENV['doc']->refresheditlock($this->get[2],$this->user['uid']);
		eval($this->plugin['hdapi']['hooks']['refreshlock']);
	}

	function dounseteditlock(){
		$_ENV['doc']->unset_editlock($this->get[2],$this->user['uid']);
		eval($this->plugin['hdapi']['hooks']['unlockdoc']);
		$this->header("doc-view-".$this->get[2]);
	}

	function doinnerlink(){
		$len=strlen('doc-innerlink-');
		$title=substr($_SERVER['QUERY_STRING'],$len);
		$title=string::hiconv(trim(urldecode($title)));
		$doc=$_ENV['doc']->get_doc_by_title($title);
		if(!(bool)$doc){			
			$doc=$_ENV['synonym']->get_synonym_by_src($title);
			if($doc){
				//$this->header("doc-view-".$doc['destdid']);
				$this->header("synonym-view-".$doc['id']);
			}else{
				$this->view->assign("title",$title);
				$this->view->display("notexist");
			}
			
		}else{
			$this->header("doc-view-".$doc['did']);
		}
	}

	function dosummary(){
		$count=count($this->get);
		@$title=$this->get[2];
		for($i=3;$i<$count;$i++){
			$title .='-'.$this->get[$i];
		}
		$title=trim(urldecode($title));
		if(string::hstrtoupper(WIKI_CHARSET)=='GBK'){
			$title=string::hiconv($title,$to='gbk',$from='utf-8');
		}
		$doc=$_ENV['doc']->get_doc_by_title($title);
		if((bool)$doc){
			$doc['image']=util::getfirstimg($doc['content']);
			$doc['url']=$this->setting['site_url']."/".$this->setting['seo_prefix']."doc-view-".$doc['did'].$this->setting['seo_suffix'];
			$doc_exists=1;
		}else{
			$doc_exists=0;
		}
		$this->view->assign("doc_exists",$doc_exists);
		$this->view->assign("doc",$doc);
		$this->view->assign("encode",WIKI_CHARSET);
		$this->view->assign("title",$title);
		$this->view->display('hdmomo');
	}

	function dosandbox(){
		$did = $this->setting['sandbox_id'];
		$maxid =  $_ENV['doc']->get_maxid();
		
		if (!is_numeric($did) || $did < 1 || $did > $maxid){
			$did = $maxid;
		}
		if($did){
			$this->header('doc-edit-'.$did);
		}else{
			$this->message($this->view->lang['sandboxTip1'],'index.php',0);
		}
	}
	
	function dosetfocus(){
		if(@!is_numeric($this->post['did'])){
			$this->message("-1","",2);
		}elseif(@$this->post['visible']!="1"){
			$this->message("-2","",2);
		}elseif($_ENV['doc']->set_focus_doc(array($this->post['did']))){
			$this->cache->removecache('indexcache');
			$this->message("1","",2);
		}else{
			$this->message("0","",2);
		}
	}

	function dogetcategroytree(){
		$all_category=$_ENV['category']->get_category_cache();
		$categorytree=$_ENV['category']->get_categrory_tree($all_category);
		$this->message($categorytree,"",2);
	}
	
	function dochangename(){
		$ajaxtitle=string::hiconv(trim($this->post['newname']));
		$title=string::substring(string::stripscript($_ENV['doc']->replace_danger_word(trim($ajaxtitle))),0,80);
		if(@!is_numeric($this->post['did'])){
			$this->message("-1","",2);
		}elseif($ajaxtitle!=string::stripscript($ajaxtitle)){
			$this->message("-3","",2);
		}elseif(@(bool)$_ENV['doc']->get_doc_by_title($title)){
			$this->message("-2","",2);
		}elseif($_ENV['doc']->change_name($this->post['did'],$title)){
			$_ENV['synonym']->synonym_change_doc($this->post['did'],$title);
			$this->message("1","",2);
		}else{
			$this->message("0","",2);
		}
	}
	
	function dochangecategory(){
		if(@is_numeric($this->post['did'])&&@is_numeric($this->post['newcategory'])){
			$category=$_ENV['category']->get_category($this->post['newcategory']);
			if((bool)$category && $_ENV['doc']->change_category(array($this->post['did']),$this->post['newcategory'])){
				$_ENV['category']->update_category_docs($this->post['newcategory']);
				$_ENV['category']->update_category_docs($this->post['oldcategory'],'-1');
				$result='';
				foreach(unserialize($category['navigation']) as $value){
					@$result .="&gt;&gt; <a href=\"".$this->setting['seo_prefix']."category-view-{$value['cid']}".$this->setting['seo_suffix']."\" > {$value['name']} </a>";
				}
				$this->message($result,"",2);
			}
		}else{
			$this->message("0","",2);
		}
	}

	function dolock(){
		if(@is_numeric($this->post['did'])&&(bool)$_ENV['doc']->lock(array($this->post['did']))){
			$this->message("1","",2);
		}else{
			$this->message("0","",2);
		}
	}

	function dounlock(){
		if(@is_numeric($this->post['did'])&&(bool)$_ENV['doc']->lock( array($this->post['did']),0)){
			$this->message("1","",2);
		}else{
			$this->message("0","",2);
		}
	}

	function doaudit(){
		if(@is_numeric($this->post['did'])&&(bool)$_ENV['doc']->audit_doc(array($this->post['did']))){
			$this->message("1","",2);
		}else{
			$this->message("0","",2);
		}
	}

	function doremove(){
		if(@!is_numeric($this->get[2])){
			$this->message($this->view->lang['parameterError'],'BACK',0);
		}else{
			$_ENV['doc']->remove_doc(array($this->get[2]));
			$_ENV['synonym']->removesynonym(array($this->get[2]));
			$this->header("category-view-".$this->get[3]);
		}
	}
	
	
	function dorandom(){
		$did=$_ENV['doc']->get_random();
		if(0==$did){
			$this->header();
		}else{
			$this->header('doc-view-'.$did);
		}
	}
	
	function dovote(){
		if(@is_numeric($this->post['did'])){
			$did=$this->post['did'];
			@$hdvote = $this->hgetcookie('vote'.$did);
			if(!isset($hdvote)){
				$_ENV['doc']->update_field('votes',1,$did,0);
				$this->hsetcookie('vote'.$did,$did);
				$this->message('1','',2);
			}
		}
		$this->message('0','',2);
	}

}

?>